package com.cunjin.base.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class DuanxinUtil {

	public static void phoneSecurity(int code,String phonenum) throws IOException 
	{
		
		
		
		URL url = new URL("http://www.lanz.net.cn/LANZGateway/DirectSendSMSs.asp");
		HttpURLConnection connection = (HttpURLConnection)url.openConnection();
                connection.setRequestMethod("POST");
		connection.setDoOutput(true);
                connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");              
		OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "GB2312");

		  String urlString = "UserID=707494&Account=17688893232&Password=C1358B73F72D8A8AB8CF073A1D60905B1BC53704"
				  +"&Content=您的注册验证码为"+code+"，该验证码10分钟内有效。如非本人操作请忽略此短信！【浪驰软件】"
				  +"&Phones="+phonenum+"&ReturnXJ=1";
          
		urlString = urlString.replace("%","％");
		urlString = urlString.replace("+","＋");
		urlString = urlString.replace(" ","+");


		out.write(urlString);
		out.flush();
		out.close();
		
		String sCurrentLine;
		String sTotalString;
		sCurrentLine = "";
		sTotalString = "";
		InputStream l_urlStream;
		l_urlStream = connection.getInputStream();

		BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
		while ((sCurrentLine = l_reader.readLine()) != null) 
		{
			sTotalString += sCurrentLine + "\r\n";
		}
		System.out.println(sTotalString);
	}
	
	
	public static int getCode(){
		//产生一个随机4位数
		int code=(int) (Math.random()*9000)+1000;
		return code;
	}
	
	//模板是要付费使用的
	public static void main(String[] args) throws IOException
	 {
//         testPost(1234,"15766472116");
		/*for(int i=0;i<1000;i++){
			int a=(int) (Math.random()*9000)+1000;
			System.out.println(a);
			
		}*/
	 }

}